package com.mapper.sales;

import com.pojo.Product;
import com.pojo.sales.view.SalesProductR;
import com.pojo.sales.view.SalesTop5ProductView;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 产品映射器
 *
 * @author admin
 * @date 2023/06/19
 */
@Mapper
public interface ProductMapper {
    /**
     * 销售产品
     *
     * @return {@link List}<{@link SalesProductR}>
     */
    @Select("select product_id productId," +
            " product_name productName," +
            " product_description productDescription," +
            " product_price productPrice," +
            " product_quantity productQuantity " +
            "from sales_product_r " +
            "order by product_quantity desc ")
    List<SalesProductR> getSaleProducts();

    /**
     * 本月前五名销售产品
     *
     * @return {@link List}<{@link SalesTop5ProductView}>
     */
    @Select("SELECT product_name AS productName, product_quantity AS productQuantity, sales_date AS salesDate \n" +
            "FROM sales_top5product_view\n" +
            "WHERE sales_date >= DATE_FORMAT(NOW(), '%Y-%m-01')\n" +
            "ORDER BY productQuantity DESC \n" +
            "LIMIT 5")
    List<SalesTop5ProductView> getTopFiveSaleProduct();


    Product queryProductById(Long id);

    /**
     * 获取产品价格
     *
     * @param id     ID
     * @param sizeId 尺寸id。
     * @return {@link Product}
     */
    Product getProductPrice(@Param("id") Integer id, @Param("sizeId") Integer sizeId);


}
